<!DOCTYPE html>
<html>
<head>
  <script src="../../processing.js"></script>
<link rel="stylesheet" href="../style.css"/></head>
<body><h1><a href="http://ejohn.org/blog/processingjs/">Processing.js</a></h1>
<h2>Translate</h2>

<p>The translate() function allows objects to be moved
to any location within the window. The first parameter
sets the x-axis offset and the second parameter sets the
y-axis offset.</p>

<p><a href="http://processing.org/learning/basics/translate.html"><b>Original Processing.org Example:</b> Translate</a><br>
<script type="application/processing">
float x, y;
float s = 40.0;

void setup() 
{
  size(200,200);
  noStroke();
  frameRate(30);
}

void draw() 
{
  background(102);
  
  x = x + 0.8;
  
  if (x > width + s) {
    x = -s;
  } 
  
  translate(x, height/2-s/2);
  fill(255);
  rect(-s/2, -s/2, s, s);
  
  // Transforms accumulate.
  // Notice how this rect moves twice
  // as fast as the other, but it has
  // the same parameter for the x-axis value
  translate(x, s);
  fill(0);
  rect(-s/2, -s/2, s, s);
}
</script><canvas width="200" height="200"></canvas></p>
<div style="height:0px;width:0px;overflow:hidden;"></div>

<pre><b>// All Examples Written by <a href="http://reas.com/">Casey Reas</a> and <a href="http://benfry.com/">Ben Fry</a>
// unless otherwise stated.</b>
float x, y;
float s = 40.0;

void setup() 
{
  size(200,200);
  noStroke();
  frameRate(30);
}

void draw() 
{
  background(102);
  
  x = x + 0.8;
  
  if (x &gt; width + s) {
    x = -s;
  } 
  
  translate(x, height/2-s/2);
  fill(255);
  rect(-s/2, -s/2, s, s);
  
  // Transforms accumulate.
  // Notice how this rect moves twice
  // as fast as the other, but it has
  // the same parameter for the x-axis value
  translate(x, s);
  fill(0);
  rect(-s/2, -s/2, s, s);
}</pre>
</body>
</html>
